package socket;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
    public class Client1 extends JFrame {
        private JTextArea chatArea;
        private JTextField inputField;
        private JButton sendButton;

        public Client1() {
            initializeUI();
        }

        private void initializeUI() {
            // 设置窗口大小
            setSize(400, 300);
            setTitle("Chat Client");
            setDefaultCloseOperation(EXIT_ON_CLOSE);

            // 使用FlowLayout布局管理器
            setLayout(new FlowLayout());

            // 创建一个滚动面板和文本区域用来显示聊天记录
            chatArea = new JTextArea(15, 50);
            chatArea.setEditable(false); // 禁止编辑
            JScrollPane scrollPane = new JScrollPane(chatArea);
            add(scrollPane);

            // 输入框
            inputField = new JTextField(20);
            add(inputField);

            // 发送按钮
            sendButton = new JButton("发送");
            sendButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String message = inputField.getText().trim();
                    if (!message.isEmpty()) {
                        chatArea.append("You: " + message + "\n");
                        inputField.setText(""); // 清空输入框
                        // 这里应该添加发送消息到服务器的逻辑
                    }
                }
            });
            add(sendButton);

            setVisible(true);
        }

        public static void main(String[] args) {
            new Client1();
        }
    }


